home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Video
/
World of Video.iso
/
programs
/
wb
/
amigaeyes
/
eyessource.lha
/
eyes.c
next >
Wrap
C/C++ Source or Header
|
1994-07-07
|
10KB
|
378 lines
/*****************************************************************************/
/* AmigaEyes */
/* */
/* Author: Stéphane Poirier */
/* Copyright © 1994 Stéphane Poirier. All right reserved */
/* */
/*****************************************************************************/
/*****************************************************************************/
/* Programme principal */
/*****************************************************************************/
#include <exec/types.h>
#include <ctype.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/clip.h>
#include <graphics/view.h>
#include <graphics/layers.h>
#include <graphics/copper.h>
#include <graphics/regions.h>
#include <graphics/rastport.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/gels.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/icon_protos.h>
#include <clib/utility_protos.h>
#include <clib/dos_protos.h>
#include <string.h>
#include <clib/diskfont_protos.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <exec/memory.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <time.h>
#include "eyes.h"
struct parametres Parametres;
unsigned int clockInit[2];
USHORT refresh;
extern int EyeCloseWindow(int);
void ToolTypesParameters(struct WBArg *);
void ValeursParDefaut(void);
UBYTE *toolTypes[]=
{
"AUTOFRONT=ON|OFF",
"TIMEOUT=n",
"BACKGROUND=n",
"BORDER=n",
"PUPIL=n",
"EYELIP=n",
"WINDOW=n",
"XPOS=n",
"YPOS=n",
"PRIORITY=n",
"REFRESH=n",
NULL
};
struct Library *GfxBase;
struct Library *DosBase;
static struct Screen *Scr = NULL;
static UBYTE *PubScreenName = NULL;
static APTR VisualInfo = NULL;
static struct Window *EyeWnd = NULL;
static struct BitMap SBitmap;
struct IntuiMessage EyeMsg;
static struct TextFont *Font = NULL;
static UWORD EyeLeft = 530;
static UWORD EyeTop = 2;
static UWORD EyeWidth = 94;
#ifdef ENTRELACE
static UWORD EyeHeight = 40;
#else
static UWORD EyeHeight = 21;
#endif
static UBYTE *EyeWdt = (UBYTE *)"Eyes";
/*****************************************************************************/
void errorMessage(STRPTR error)
{
if (error)
printf("Error: %s\n", error);
}
/*****************************************************************************/
int SetupScreen( void )
{
if ( ! ( Scr = LockPubScreen( PubScreenName )))
return( 1L );
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
return( 0L );
}
/*****************************************************************************/
void CloseDownScreen( void )
{
if ( VisualInfo ) {
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
if ( Font ) {
CloseFont( Font );
Font = NULL;
}
}
/*****************************************************************************/
int HandleEyeIDCMP( void )
{
struct IntuiMessage *m;
BOOL running = TRUE;
while( m = GT_GetIMsg( EyeWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&EyeMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( EyeMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( EyeWnd );
GT_EndRefresh( EyeWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = EyeCloseWindow(running);
break;
break;
}
}
return( running );
}
/*****************************************************************************/
int OpenEyeWindow( void )
{
UWORD offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
if ( ! ( EyeWnd = OpenWindowTags( NULL,
WA_Left, EyeLeft,
WA_Top, EyeTop,
WA_Width, EyeWidth,
WA_Height, EyeHeight + offy,
WA_SuperBitMap, &SBitmap,
WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE,
WA_Flags, WFLG_GIMMEZEROZERO|WFLG_DRAGBAR|WFLG_SUPER_BITMAP|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_REPORTMOUSE|WFLG_ACTIVATE,
WA_Title, EyeWdt,
WA_ScreenTitle, " Big Brother is watching you !",
WA_PubScreen, Scr,
TAG_DONE )))
return( 0L );
GT_RefreshWindow( EyeWnd, NULL );
return( (int)offy );
}
/*****************************************************************************/
void CloseEyeWindow( void )
{
if ( EyeWnd ) {
CloseWindow( EyeWnd );
EyeWnd = NULL;
}
}
/*****************************************************************************/
void main(int argc, char **argv)
{
struct WBArg *wbarg;
struct WBStartup *WBenchMsg;
LONG i;
int ret, offy, depth;
BOOL running = TRUE;
BOOL reveil;
if (NULL == (DosBase = OpenLibrary("dos.library", 37)))
errorMessage( "Requires V37 dos.library");
else
{
if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
errorMessage( "Requires V37 intuition.library");
else
{
if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
errorMessage( "Requires V37 graphics.library");
else
{
if (NULL == (GadToolsBase = OpenLibrary("gadtools.library", 37)))
errorMessage( "Requires V37 gadtools.library");
else
{
if ((ret = SetupScreen()) == NULL)
{
ret = timer(clockInit); /* initialise l'horloge */
ValeursParDefaut(); /* Valeurs par défaut */
WBenchMsg = (struct WBStartup *)argv; /* Arguments du Wb */
wbarg = WBenchMsg->sm_ArgList;
for(i = 0; i < WBenchMsg->sm_NumArgs; i++, wbarg++)
ToolTypesParameters(wbarg); /* ToolTypes ! */
depth = Scr->RastPort.BitMap->Depth; /* Initialise ma... */
InitBitMap(&SBitmap, depth, WNDX, WNDY); /* superbitmap */
for (i = 0; i < depth; i++)
if((SBitmap.Planes[i] = AllocRaster(WNDX, WNDY)) == NULL)
printf("erreur\n");
if ((offy = OpenEyeWindow()) != NULL) /* Initialise ma fenêtre */
{
InitEyes(EyeWnd,&SBitmap);
InitPlot(EyeWnd,&SBitmap);
while (running == TRUE)
{
Delay (refresh);
running = HandleEyeIDCMP();
reveil = DrawingEyes(EyeWnd, &SBitmap, offy);
if ((reveil) && (Parametres.autofront))
{
WindowToFront(EyeWnd);
}
}
CloseEyeWindow();
CloseDownScreen();
for (i = 0; i < depth; i++)
FreeRaster(SBitmap.Planes[i],WNDX, WNDY);
}
else printf("erreur window\n");
}
else printf("erreur screen\n");
CloseLibrary(GadToolsBase);
}
CloseLibrary(GfxBase);
}
CloseLibrary(IntuitionBase);
}
CloseLibrary(DosBase);
}
}
/*****************************************************************************/
/* Traitement des ToolTypes */
/*****************************************************************************/
void ToolTypesParameters(struct WBArg *wbarg)
{
struct DiskObject *dobj;
char **toolarray;
char *s;
struct Task *task;
UBYTE ancpriorite;
task = FindTask(NULL);
if((*wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
{
toolarray = (char **)dobj->do_ToolTypes;
if (s = (char *)FindToolType(toolarray,"AUTOFRONT"))
{
if(MatchToolValue(s,"ON"))
Parametres.autofront = TRUE;
if(MatchToolValue(s,"OFF"))
Parametres.autofront = FALSE;
}
if (s = (char *)FindToolType(toolarray,"TIMEOUT"))
{
if (isalnum(*s))
Parametres.timeout = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"BACKGROUND"))
{
if (isalnum(*s))
Parametres.fond = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"BORDER"))
{
if (isalnum(*s))
Parametres.bord = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"PUPIL"))
{
if (isalnum(*s))
Parametres.pupille = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"EYELIP"))
{
if (isalnum(*s))
Parametres.paupiere = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"WINDOW"))
{
if (isalnum(*s))
Parametres.fenetre = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"XPOS"))
{
if (isalnum(*s))
EyeLeft = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"YPOS"))
{
if (isalnum(*s))
EyeTop = (atoi(s));
}
if (s = (char *)FindToolType(toolarray,"PRIORITY"))
{
if ((isalnum(*s)) || ((*s) = '-') || ((*s) = '+'))
ancpriorite = SetTaskPri(task,atoi(s));
}
if (s = (char *)FindToolType(toolarray,"REFRESH"))
{
if (isalnum(*s))
Parametres.refresh = (atoi(s));
}
FreeDiskObject(dobj);
}
}
/*****************************************************************************/
void ValeursParDefaut(void)
{
Parametres.autofront = FALSE;
Parametres.timeout = 30;
Parametres.pupille = 1;
Parametres.bord = 1;
Parametres.fond = 2;
Parametres.paupiere = 3;
Parametres.fenetre = 0;
Parametres.refresh = 2;
refresh = SLEEP;
}